<html>
<head><meta charset="utf-8"><title>lazy norm and cycles · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html">lazy norm and cycles</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="159361424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159361424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159361424">(Feb 25 2019 at 18:49)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="124288">@oli</span>, <span class="user-mention" data-user-id="119009">@eddyb</span> -- I'm trying to dig more into the lazy normalization situation. I've asked before but I'm looking for a simple example of the sort of thing that causes a problem today (I'm trying to prep a plan as part of Traits WG, and having concrete example to work from would be great). Skimming github issue threads etc I didn't find what I was looking for.</p>
<p>I do have this example (<a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=76bc33f1650f6cb373608e9b5e28c35f" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=76bc33f1650f6cb373608e9b5e28c35f">playground</a>):</p>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">bytes</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">()],</span><span class="w"></span>
<span class="w">    </span><span class="n">data</span>: <span class="nc">T</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</pre></div>


<p>but right now it errors out because it can't prove <code>T: Sized</code>. I have some vague memory that maybe we don't use the true parameter environment (because of cycles, perhaps?) and hence this is why we have this problem?</p>



<a name="159445659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159445659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159445659">(Feb 26 2019 at 18:32)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="121053">@varkor</span> <span aria-label="point up" class="emoji emoji-1f446" role="img" title="point up">:point_up:</span> are you familiar with this question as well?</p>



<a name="159445946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159445946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159445946">(Feb 26 2019 at 18:37)</a>:</h4>
<p>So... the array length constant is essentially a new (but anonymous) item. Unlike associated constants they do not look into their parents for generics.  I wonder if it would be enough to just treat them like impl trait (anonymous existential types) and give them access to their parent's scope. I mean this would be easy to feature gate, so we can experiment. I don't see anything immediately problematic.</p>



<a name="159445979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159445979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159445979">(Feb 26 2019 at 18:37)</a>:</h4>
<p>Hmm.</p>



<a name="159446026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446026">(Feb 26 2019 at 18:38)</a>:</h4>
<p>Cycles already exist if we try to use anything interesting from <code>Foo</code> during the computation of the array length:</p>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">bytes</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;</span><span class="n">Foo</span><span class="o">&lt;</span><span class="kt">u32</span><span class="o">&gt;&gt;</span><span class="p">()],</span><span class="w"></span>
<span class="w">    </span><span class="n">data</span>: <span class="nc">T</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="159446040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446040">(Feb 26 2019 at 18:38)</a>:</h4>
<p>That's a different cycle</p>



<a name="159446058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446058">(Feb 26 2019 at 18:38)</a>:</h4>
<p>That is, it seems like a kind of "legit" cycle</p>



<a name="159446059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446059">(Feb 26 2019 at 18:38)</a>:</h4>
<p>it is, but I don't see how going directly through <code>T</code> could be worse</p>



<a name="159446069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446069">(Feb 26 2019 at 18:38)</a>:</h4>
<p>Oh, I would expect the code above to work</p>



<a name="159446113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446113">(Feb 26 2019 at 18:39)</a>:</h4>
<p>so would I. I understood your question as "is there code that would fail even though we'd think it was sane"</p>



<a name="159446126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446126">(Feb 26 2019 at 18:39)</a>:</h4>
<p>but I'm trying to get at the problem that <span class="user-mention" data-user-id="119009">@eddyb</span> is talking about where const generics are blocked on lazy norm. I think a better example is :</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">()</span><span class="w"></span>
<span class="k">where</span><span class="w"> </span><span class="n">T</span>: <span class="nc">Foo</span><span class="o">&lt;</span><span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="mi">22</span><span class="p">]</span><span class="o">&gt;</span><span class="w"></span>
<span class="p">{</span><span class="w"> </span><span class="p">..</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</pre></div>


<p>where here the problem would be that to "normalize" the <code>22</code> expression (compute its value), we would need to know the predicates from the surrounding fn, but of course to get those we have to normalize.</p>
<p>We solve this for associated types with a rather special purpose evaluation.</p>



<a name="159446197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446197">(Feb 26 2019 at 18:40)</a>:</h4>
<p>I've asked them for examples before and I can't seem to find those messages in my chat history</p>



<a name="159446256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446256">(Feb 26 2019 at 18:41)</a>:</h4>
<p>normalizing the <code>22</code> would probably not immediately cause cycles. Only if the value actually tried to use <code>T</code> in an interesting manner</p>



<a name="159446366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446366">(Feb 26 2019 at 18:42)</a>:</h4>
<p>we're probably going to have some degenerate cases, but these are errors where we want to allow something and not the inverse</p>



<a name="159446433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446433">(Feb 26 2019 at 18:42)</a>:</h4>
<p>I don't think that's true</p>



<a name="159446454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446454">(Feb 26 2019 at 18:42)</a>:</h4>
<p>That is, I think that -- if we use a naive impl -- any normalization would trigger a cycle</p>



<a name="159446506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446506">(Feb 26 2019 at 18:43)</a>:</h4>
<p>because of the <code>ParamEnv</code> computation?</p>



<a name="159446510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446510">(Feb 26 2019 at 18:43)</a>:</h4>
<p>( just because we are invoking <code>predicates_of</code> )</p>



<a name="159446552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446552">(Feb 26 2019 at 18:43)</a>:</h4>
<p>let me go review how the code is setup here I guess</p>



<a name="159446556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446556">(Feb 26 2019 at 18:44)</a>:</h4>
<p>I'm kind of just guessing</p>



<a name="159446654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446654">(Feb 26 2019 at 18:44)</a>:</h4>
<p>not any of the const eval code (I just checked to be sure)</p>



<a name="159446665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446665">(Feb 26 2019 at 18:44)</a>:</h4>
<p>so it could be the normalization around it</p>



<a name="159446820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446820">(Feb 26 2019 at 18:46)</a>:</h4>
<p>so there's this <a href="https://github.com/rust-lang/rust/blob/ea43c3c688980edd6f09a4cb632c9eb996c4f2af/src/librustc/traits/project.rs#L399-L432" target="_blank" title="https://github.com/rust-lang/rust/blob/ea43c3c688980edd6f09a4cb632c9eb996c4f2af/src/librustc/traits/project.rs#L399-L432">kind of complex logic around normalizing constants</a></p>



<a name="159446871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446871">(Feb 26 2019 at 18:47)</a>:</h4>
<p>jup, looking through that right now. We do have the call to <code>Instance::resolve</code> that might be problematic</p>



<a name="159446874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159446874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159446874">(Feb 26 2019 at 18:47)</a>:</h4>
<p>I'm trying to reconstruct in my mind the reasoning behind this :)</p>



<a name="159447381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159447381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159447381">(Feb 26 2019 at 18:52)</a>:</h4>
<p>I wish we had a callgraph of rustc XD the rabbit hole is pretty deep</p>



<a name="159447543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159447543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159447543">(Feb 26 2019 at 18:54)</a>:</h4>
<p>it feels to me like the logic in <code>Instance::resolve</code> and the logic in <a href="http://project.rs" target="_blank" title="http://project.rs">project.rs</a> is duplicated, and that's part of the problem</p>



<a name="159447555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159447555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159447555">(Feb 26 2019 at 18:54)</a>:</h4>
<p>i.e., I'd expect normalizing constants to work more like associated types</p>



<a name="159447570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159447570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159447570">(Feb 26 2019 at 18:54)</a>:</h4>
<p>but I'm trying to remember why .. I should actually check the PR where this was added, I have a memory of chatting a bit with <span class="user-mention" data-user-id="119009">@eddyb</span> about it</p>



<a name="159453496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159453496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159453496">(Feb 26 2019 at 20:04)</a>:</h4>
<p>I know <span class="user-mention" data-user-id="119009">@eddyb</span> gave me an example of where this is would be an issue with const generics, but I can't remember off the top of my head</p>



<a name="159463811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159463811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159463811">(Feb 26 2019 at 22:17)</a>:</h4>
<blockquote>
<p>Oh, I would expect the code above to work</p>
</blockquote>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> just to be clear, by "above", you are referring to <code>[u8; std::mem::size_of::&lt;T&gt;()]</code> or also <code>[u8; std::mem::size_of::&lt;Foo&lt;u32&gt;&gt;()]</code>?</p>
<p>The latter requires knowing the layout of <code>struct Foo_u32 { bytes: [u8; size_of::&lt;Foo_u32&gt;()], data: u32 }</code> which should produce a cycle...?</p>



<a name="159463963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/lazy%20norm%20and%20cycles/near/159463963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/lazy.20norm.20and.20cycles.html#159463963">(Feb 26 2019 at 22:18)</a>:</h4>
<blockquote>
<p>So... the array length constant is essentially a new (but anonymous) item. Unlike associated constants they do not look into their parents for generics. I wonder if it would be enough to just treat them like impl trait (anonymous existential types) and give them access to their parent's scope. I mean this would be easy to feature gate, so we can experiment. I don't see anything immediately problematic.</p>
</blockquote>
<p><span class="user-mention" data-user-id="124288">@oli</span>   A more principled treatment of this might be to introduce <a href="https://www.microsoft.com/en-us/research/publication/lexically-scoped-type-variables/" target="_blank" title="https://www.microsoft.com/en-us/research/publication/lexically-scoped-type-variables/">ScopedTypeVariables</a> at large; would be useful in general; but I'm not opposed to experimentation with a subset <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>